<template>
  <div>
    <el-table
        :data="tableData"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          fixed
          prop="buynumber"
          label="采购编号"
          width="150">
      </el-table-column>
      <el-table-column
          prop="goodsname"
          label="商品名称"
          width="120">
      </el-table-column>
      <el-table-column
          prop="type"
          label="商品类型"
          width="120">
      </el-table-column>
      <el-table-column
          prop="offernum"
          label="中标报价"
          width="120">
      </el-table-column>
      <el-table-column
          prop="buynum"
          label="采购数量"
          width="100">
      </el-table-column>
      <el-table-column
          prop="sufdate"
          label="中标日期"
          width="100">
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5,10,15,20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next"
          :total="pageTotal">
      </el-pagination>
    </div>
    <div style="margin-top: 20px">
      <el-button @click="open">发起供货</el-button>
      <el-button @click="toggleSelection()">取消选择</el-button>
    </div>
    <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose"
        v-loading="loading">
      <span></span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>


  </div>
</template>

<script>
export default {
  name: "BidView",
  data() {
    return {
      tableData: [],
      multipleSelection: [],
      loading: false,
      dialogVisible: false,
      pageSize: 5,
      pageTotal: 0,
      currentPage: 1,
    }
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.$axios.get("/psc/successful/getSucByPage/" + this.currentPage + "/" + this.pageSize + "/" + sessionStorage.getItem("userNumber") + "").then(
          r => {
            this.tableData = r.data.list;
            this.pageTotal = r.data.pageTotal;
          }
      )
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.init()
    }, handleCurrentChange(val) {
      this.currentPage = val
      this.init()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }, open() {
      this.$alert('你确定要请求付款嘛？', '付款信息', {
        confirmButtonText: '确定',
        callback: action => {
          this.supply(action);
        }
      });
    },
    supply(action) {
      console.log(action)
      if (this.multipleSelection.length == 0) {
        this.$message.error("请选择中标商品")
      } else {
        console.log(this.multipleSelection)
        // this.dialogVisible=true;
        // this.loading=true;

        for (let i = 0; i < this.multipleSelection.length; i++) {
          let a = this.multipleSelection[i];
          let fd = new FormData();
          fd.append("buynumber", a.buynumber)
          fd.append("usernumber", a.usernumber);
          fd.append("ordernum", a.buynum)
          fd.append("orderprice", a.offernum)
          fd.append("type", a.type)
          console.log(fd)
          this.$axios.post("/psc/order/supply", fd).then(
              r => {
                if (r.data) {
                  this.init();
                  this.$message.success("发起供货成功，系统付款中")
                } else {
                  this.$message.error("发起供货失败，请重新发货")
                }
              }
          )
        }

      }
    }, toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    }
  }
}
</script>

<style scoped>

</style>